#ifndef _PACKETTYPEFILTER_H_
#define _PACKETTYPEFILTER_H_

#include <typeinfo>
#include <string>

#include <filter/PacketFilter.h>

class Packet;

/**
 * Filters for packets of a particular type. The type is given as a Class object, so
 * example types would:
 * <ul>
 *      <li><tt>Message.class</tt>
 *      <li><tt>IQ.class</tt>
 *      <li><tt>Presence.class</tt>
 * </ul>
 *
 * @author Matt Tucker
 */
class PacketTypeFilter : public PacketFilter {
public:

    /**
     * Creates a new packet type filter that will filter for packets that are the
     * same type as <tt>packetType</tt>.
     *
     * @param packetType the Class type.
     */
    PacketTypeFilter(const std::type_info& packetType) : packetType(&packetType) { }

    // Access for the wrapped std::type_info
    const std::type_info& Get() const;
    // Compatibility functions
    bool before(const PacketTypeFilter& rhs) const;
    const char* name() const;

    bool accept(Packet * packet) ;

	std::string toString() ;
private:
	const std::type_info* packetType;
};


// Comparison operators

inline bool operator==(const PacketTypeFilter& lhs, const PacketTypeFilter& rhs)
{ return (lhs.Get() == rhs.Get()) != 0; }

inline bool operator<(const PacketTypeFilter& lhs, const PacketTypeFilter& rhs)
{ return lhs.before(rhs); }

inline bool operator!=(const PacketTypeFilter& lhs, const PacketTypeFilter& rhs)
{ return !(lhs == rhs); }    

inline bool operator>(const PacketTypeFilter& lhs, const PacketTypeFilter& rhs)
{ return rhs < lhs; }

inline bool operator<=(const PacketTypeFilter& lhs, const PacketTypeFilter& rhs)
{ return !(lhs > rhs); }

inline bool operator>=(const PacketTypeFilter& lhs, const PacketTypeFilter& rhs)
{ return !(lhs < rhs); }

#endif // -- _PACKETTYPEFILTER_H_
